/**
 * Created with IntelliJ IDEA.
 * Description: 无参的构造的方法和有参的构造的方法，封装
 * User: 86183
 * Date: 2022-09-29
 * Time: 9:37
 */
class Student{
    //定义私有的成员变量：姓名和分数，只能在类内访问，实现封装。
    private  int score;
    private  String name;
    //定义公开的访问方法
    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //无参的构造方法
    public Student() {
    }
   //有参的构造方法
    public Student(int score, String name) {
        this.score = score;
        this.name = name;
    }
    public void Myprint(){
        System.out.println(getName()+"考了"+getScore());
    }
}
public class Test {
    public static void main(String[] args){
        Student s1 = new Student();//调用无参的构造方法
        //调用公开的方法，给成员赋值
        s1.setScore(100);
        s1.setName("王雅钊");
        s1.Myprint();
        Student s2 = new Student(99,"王雅钊");//调用有参的构造方法
        s2.Myprint();
    }

}
